package com.meichis.yndms.adapter.RecycleViewItemType;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.meichis.mcsappframework.adapter.recyclerview.base.ItemViewDelegate;
import com.meichis.mcsappframework.adapter.recyclerview.base.ViewHolder;
import com.meichis.yndms.R;
import com.meichis.yndms.model.InspectTemplate_Item;
import com.meichis.yndms.ui.activity.VST_FreeQuestionnaireLogicActivity;

import java.util.List;


public class FillMode_TDP implements ItemViewDelegate<InspectTemplate_Item>, View.OnClickListener {

    private final Activity activity;
    private List<InspectTemplate_Item> items;
    private Context context;

    public FillMode_TDP(Context context, Activity activity, List<InspectTemplate_Item> items) {
        this.items = items;
        this.context = context;
        this.activity = activity;

    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.fill_mode_tdp;
    }

    @Override
    public boolean isForViewType(InspectTemplate_Item item, int position) {
        return item.getItem().getFillMode() == 22;
    }

    @Override
    public void convert(ViewHolder holder, InspectTemplate_Item inspectTemplate_item, int position) {
        TextView tv_answer = holder.getView(R.id.tv_answer);
        TextView tv_question = holder.getView(R.id.tv_question);
        tv_question.setText(Html.fromHtml(String.valueOf(position + 1) + ". " +
                inspectTemplate_item.getItem().getName().replace("<", "&lt;") +
                (!TextUtils.isEmpty(inspectTemplate_item.getItem().getUnit()) ? "(" + inspectTemplate_item.getItem().getUnit() + ")" : "") +
                (inspectTemplate_item.getIsMustFill() == 1 ? " <font  color=\"#FF0000\">*</font>" : "") +
                (!TextUtils.isEmpty(inspectTemplate_item.getItem().getSubTitle()) ? "<br/> <font color=\"#8D8D8D\" ><small>" + inspectTemplate_item.getItem().getSubTitle() + "</small></font>" : "")
        ));
        tv_answer.setText(inspectTemplate_item.getFillName());
        tv_answer.setTag(position);
        tv_answer.setOnClickListener(this);

        LinearLayout ll = holder.getView(R.id.ll_answer);
        setBackground(inspectTemplate_item, ll);
    }

    @Override
    public void onClick(View view) {
//        int position = (Integer) view.getTag();
//        Intent intent = new Intent(context, TDPListActivity.class);
//        intent.putExtra("Position",position);
//        context.startActivity(intent);
    }

    private void setBackground(InspectTemplate_Item item, LinearLayout ll) {
        ll.setBackgroundResource(item.getFillName().length() == 0 && item.getIsMustFill() == 1 ? R.drawable.bg_ll_frame : R.drawable.bg_ll_frame);
    }
}
